package com.cn.kehong.service;


import com.cn.kehong.api.ISystemLogService;
import com.cn.kehong.dao.SystemLogMapper;
import com.cn.kehong.domain.SystemLog;
import com.cn.kehong.utils.CollectionsUtil;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemLogServiceImpl implements ISystemLogService {

    @Autowired
    private SystemLogMapper systemLogMapper;

    @Override
    public List<SystemLog> querySystemLogs(QueryForm queryForm) throws Exception {
        int count = systemLogMapper.selectSystemLogCount(queryForm);
        List<SystemLog> result = systemLogMapper.selectSystemLog(queryForm);
        if(CollectionsUtil.isNotEmpty(result)){
            result.get(0).setCount(count);
        }
        return result;
    }

    @Override
    public List<SystemLog> queryAllSystemLogs(QueryForm queryForm) throws Exception {
        return systemLogMapper.selectAllSystemLog(queryForm);
    }

    @Override
    public String addSystemLog(SystemLog mgSystemLog) throws Exception {
        String id = CommonUtil.generateRandomNum("log-");
        mgSystemLog.setId(id);
        int count = systemLogMapper.insertSelective(mgSystemLog);
        return CommonUtil.outStr(count);
    }

    @Override
    public String delSystemLog(SystemLog systemLog) throws Exception {
        return null;
    }
}
